//
//  MHMyHomeRootController.m
//  M-Saler
//
//  Created by Teresa on 2020/5/21.
//  Copyright © 2020 Teresa. All rights reserved.
//

#import "MHMyHomeRootController.h"
#import "THBaseTableViewCell.h"
#import "MHMyCompanyRootController.h"
#import "MHMyClientListController.h"
#import "MHMyInfoController.h"
#import "MHFeedBackController.h"

@interface MHMyHomeRootController ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet ZKPropertyButton *avatarBtn;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (copy, nonatomic) NSArray *titleArr;

@end

@implementation MHMyHomeRootController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self configUI];
    [self fillData];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear: animated];
    [self.navigationController setNavigationBarHidden:YES];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}

-(void)configUI{
    [THBaseTableViewCell registerToTableView:self.tableView];
    self.titleArr = @[@"我的公司",@"我的客户",@"意见反馈"];
    self.tableView.tableFooterView = [UIView new];
}
    
-(void)fillData{
    MHUserModel *model = [MHUserModel userModel];
    self.nameLabel.text = model.name;
    //    self.avatarBtn setImage:<#(nullable UIImage *)#> forState:<#(UIControlState)#>  //头像未知
}

#pragma mark - TableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    THBaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:THBaseTableViewCell.nameOfClass];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.text = self.titleArr[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 56.f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0://我的公司
        {
            MHMyCompanyRootController *newVC = [MHMyCompanyRootController new];
            [self.navigationController pushViewController:newVC animated:YES];
        }
            break;
        case 1://我的客户
        {
            MHMyClientListController *newVC = [[MHMyClientListController alloc]init];
            [self.navigationController pushViewController:newVC animated:YES];
        }
            break;
        case 2://意见反馈
        {
            MHFeedBackController *newVC = [[MHFeedBackController alloc]init];
            [self.navigationController pushViewController:newVC animated:YES];
        }
            break;
        default:
            break;
    }
}
- (IBAction)push2UserInfo:(id)sender {
    MHMyInfoController *newVC = [[MHMyInfoController alloc]initWithNibName:MHMyInfoController.nameOfClass bundle:nil];
    [self.navigationController pushViewController:newVC animated:YES];
}

@end
